<template lang="html">
  <div class="audit">
    <div class='searchView'>
      <el-form :inline="true" class="demo-form-inline" ref='searchForm'>
<!--         <el-form-item label="时间范围">
          <el-date-picker
            v-model="pickerValue"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item> -->

        <el-form-item label="用户名">
          <input class='el-input__inner' @keydown.enter='search' v-model='searchForm.userName' placeholder="请输入用户名">
        </el-form-item>

        <el-form-item label="IP">
          <input class='el-input__inner' @keydown.enter='search' v-model='searchForm.ip' placeholder="请输入IP">
        </el-form-item>

        <el-form-item label="模块">
          <el-select v-model="searchForm.mode" placeholder="请选择模块">
            <el-option
              v-for="item in modeList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="动作">
          <el-select v-model="searchForm.action" placeholder="请选择动作">
            <el-option
              v-for="item in actionList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="结果">
          <el-select v-model="searchForm.result" placeholder="请选择结果">
            <el-option
              v-for="item in resultList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click='search'>查询</el-button>
        </el-form-item>
      </el-form>

      <el-table
        :data="tableData"
        style="width: 100%">
        <el-table-column
          type="index"
          width="50">
        </el-table-column>
        <el-table-column
          prop="date"
          label="时间">
        </el-table-column>
        <el-table-column
          prop="userName"
          label="用户名">
        </el-table-column>
        <el-table-column
          prop="ip"
          label="IP">
        </el-table-column>
        <el-table-column
          label="模块">
          <template slot-scope="scope">
            <span v-for='i in modeList' v-if='i.value == scope.row.mode' v-text='i.label'></span>
          </template>
        </el-table-column>
        <el-table-column
          label="动作">
          <template slot-scope="scope">
            <span v-for='i in actionList' v-if='i.value == scope.row.action' v-text='i.label'></span>
          </template>
        </el-table-column>
        <el-table-column
          label="结果">
          <template slot-scope="scope">
            <span v-for='i in resultList' v-if='i.value == scope.row.result' v-text='i.label'></span>
          </template>
        </el-table-column>
        <el-table-column
          prop="msg"
          label="消息">
        </el-table-column>
      </el-table>

      <div class="pageBlock">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-size="pageSize"
          layout="prev, pager, next, jumper, sizes"
          :total="totalData">
        </el-pagination>
      </div>
    </div>
  </div>
</template>
<script>
import data from './data/auditData';
export default {
  data () {
    return {
      tableData:data,
      pickerValue:[],
      searchForm:{
        userName:'',
        ip:'',
        mode:'',
        action:'',
        result:''
      },
      modeList: [{
        value: '',
        label: '全部'
      }, {
        value: '1',
        label: '后台管理鉴权'
      }],
      actionList:[{
        value: '',
        label: '全部'
      }, {
        value: '1',
        label: '登录'
      }, {
        value: '2',
        label: '注销'
      }],
      resultList:[{
        value: '',
        label: '全部'
      },{
        value: '1',
        label: '成功'
      },{
        value: '2',
        label: '失败'
      }],
      loading:false,
      pageSize:50,
      currentPage:1,
      totalData:data.length
    }
  },
  methods:{
    search(){
      let search = tools.cloneObj(this.searchForm);
      for(let i in search){
        if(search[i] === ''){
          delete search[i]
        }
      }

      if(!tools.emptyObj(search)){
        let arr = [];
        for(let i of data){
          let has = true;
          for(let o in search){
            if(i[o].indexOf(search[o]) == -1){
              has = false;
            }
          }

          if(has){
            arr.push(i);
          }
        }

        this.tableData = arr;
      }else{
        this.tableData = data;
      }
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
      // this.getList();
    },
    unactiveIt(row){
      this.$confirm('是否确认取消激活状态',{center:true})
      .then(res =>{

        this.loading = true;
        tools.ajax({
          url:`/user_service/v1/users/${this.roleInfo.userId}/roles/${row.id}`,
          data:{
            disabled:1
          },
          type:'PUT'
        })
        .then(res => {
          this.loading = false;
          if(res.code == 200){
            tools.toastOk('取消激活成功');
            this.dialogVisible = false;
            this.getList(1);
          }
        })
        .catch(e => {
        })

      }).catch( e=> {})
    },
    tourl(url,query){
      tools.router.push({path:url,query:query || {}})
    }
  },
  mounted(){
    var _this = this;
  },
  components:{

  }
}
</script>

<style scoped lang='scss'>
@import '../../assets/scss/tool.scss';
.audit{

}
</style>
